package com.zmc.dynamic.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmc.dynamic.service.StudentService;
import com.zmc.dynamic.domain.Student;
import com.zmc.dynamic.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("slave")
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student getByStudentId(Long id) {
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        Student one = getOne(wrapper);
        if (one != null) {
            return one;
        }
        return studentMapper.getByStudentId(id);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }
}
